package com.asynctm.android.socialnetwork.dao;

import java.util.List;

import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;

import com.asynctm.android.common.exception.DaoException;

/**
 * Implemantacion de {@link TwitterDao}
 * 
 * @author rockdrigo && rodmal
 */
public class TwitterDaoImpl implements TwitterDao {

	/** Instancia de twitter4j */
	private Twitter twitter;
	
	/**
	 * 
	 */
	public TwitterDaoImpl() {
		super();
		twitter = new TwitterFactory().getInstance();
	}
	
	private Twitter getTwitter() {
		if(twitter == null) twitter = new TwitterFactory().getInstance();
		return twitter;
	}

	public List<Status> getTweets() throws DaoException {		
		try {
			List<Status> result = getTwitter().getHomeTimeline();
			return result;
		} catch (TwitterException e) {
			throw new DaoException(e);
		}
	}

	public List<Status> getUserTweets(String screenName) throws DaoException {
		try {
			List<Status> result = getTwitter().getUserTimeline(screenName);
			return result;
		} catch (TwitterException e) {
			throw new DaoException(e);
		}
	}

}
